﻿namespace UFIDA.U9.CUST.AITBarCodeRest
{
	using System;
	using System.Collections.Generic;
	using System.Text;
    using ufida.u9.ait.openapi.utils;
    using UFIDA.U9.CBO.Pub.Controller;
    using UFSoft.UBF.AopFrame;	
	using UFSoft.UBF.Util.Context;

	/// <summary>
	/// AITBarCodeTransUseSV partial 
	/// </summary>	
	public partial class AITBarCodeTransUseSV 
	{	
		internal BaseStrategy Select()
		{
			return new AITBarCodeTransUseSVImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class AITBarCodeTransUseSVImpementStrategy : BaseStrategy
	{
		public AITBarCodeTransUseSVImpementStrategy() { }

		public override object Do(object obj)
		{						
			AITBarCodeTransUseSV bpObj = (AITBarCodeTransUseSV)obj;

            try
            {
                if (bpObj.Data == null) throw new Exception("传入参数为空");
                List<CommonArchiveDataDTOData> retlist = new List<CommonArchiveDataDTOData>();

                foreach (var item in bpObj.Data)
                {
                    if (string.IsNullOrEmpty(item.BarCode)) continue;
					List<AITBarCodeUseDTOData> datas = new List<AITBarCodeUseDTOData>();
                    if (item.OutQty > 0)
					{
						//条码出库
						AITBarCodeUseDTOData data = new AITBarCodeUseDTOData();
						data.BarCode = item.BarCode;
						data.SrcDocName = item.SrcDocName;
						data.SrcDocNo = item.SrcDocNo;
						data.SrcDocLineNo=item.SrcDocLineNo;
						data.TransDirection = 1; //0-收货 1-发货 2-收发货
						data.Qty = item.OutQty;
                        datas.Add(data);
                    }
					if (item.InQty > 0)
					{
						//条码入库
                        AITBarCodeUseDTOData data = new AITBarCodeUseDTOData();
                        data.BarCode = item.BarCode;
                        data.SrcDocName = item.SrcDocName;
                        data.SrcDocNo = item.SrcDocNo;
                        data.SrcDocLineNo = item.SrcDocLineNo;
                        data.TransDirection = 0; //0-收货 1-发货 2-收发货
                        data.Qty = item.InQty;
                        datas.Add(data);
                    }
					//调用服务
                    AITBarCodeUseSV sv = new AITBarCodeUseSV();
					sv.Data = datas;
                    sv.Do();
					//处理返回
					retlist.Add(new CommonArchiveDataDTOData()
					{
						Code = item.BarCode
					});
                }

                return ResultUtils.success(bpObj, bpObj.Data, retlist);
            }
            catch (Exception ex)
            {
                return ResultUtils.error(bpObj, bpObj.Data, ex);
            }
        }		
	}

	#endregion
	
	
}